<template>
</template>

<script>
	const app = getApp();
	
	export default {
		data() {
			return {
				show: false,
				scene: '',
				phone: "",
				sjcode: "",
				openId: "",
				token: "",
				user: {},
			}
		},
		// 页面加载初始化
		onLoad(params) {
			// 清空缓存
			uni.clearStorageSync();
			this.scene = decodeURIComponent(params.scene); // 转义参数
		},
		onShow() {
			this.init();
		},

		methods: {
			// 初始化
			init() {
				this.user = app.globalData.get_user_info(this, "init", this.scene);
				if (this.user != false) {
					// 用户未绑定用户则转到登录页面
					if (app.globalData.user_is_need_login(this.user)) {
						uni.navigateTo({
							url: "/pages/login/login?event_callback=init"
						})
					} else {
						this.init_config();
					}
				}
			},
			init_config() {
				uni.showLoading({
					title: '正在绑定中,请稍候...'
				});
				let url = app.globalData.data.request_url + 'bind_account?tenantId=' + app.globalData.data.tenantId +
					'&token=' + this.user.token
				uni.request({
					url: url,
					method: 'POST',
					dataType: 'json',
					success: rres => {
						uni.hideLoading();
						if (rres.data.code == 200) {
							uni.showToast({
								title: "绑定成功"
							})
						} else {
							uni.showToast({
								title: "绑定失败,请稍候重试"
							})
						}
						setTimeout(() => {
							uni.navigateTo({
								url: "/pages/card_modify/card_modify?back=my"
							})
						}, 2000);
					},
					fail: () => {
						uni.hideLoading();
						uni.showToast({
							title: "服务器请求出错,请稍候重试"
						})
						setTimeout(function() {
							uni.switchTab({
								url: "/pages/index/index"
							});
						}, 3000);
					}
				});
			}
		}
	}
</script>

<style>
</style>